<html>
<head>
<title>Renoise Test Controller</title>
<script src="../API/RenoiseWebControl.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
function injectFunctions() {
	return "function getMasterTrack() for i, j in pairs(song().tracks) do if j.type == 2 then return j end end end;"
}

$(function(){
	connection = new Renoise(function(rns){
		rns.run(injectFunctions())
	
		rns.onMessage(function(msg){
			if(msg.masterVolume) { 
				$('.masterVolume .slider').css("width", parseInt(msg.masterVolume / 1.4125375747681 * 500) + "px")
			}
		})
						
		rns.observe('getMasterTrack().postfx_volume.value', 'masterVolume')
		rns.run('return {masterVolume = getMasterTrack().postfx_volume.value}')
		
		$('button.play').click(function() { rns.run('song().transport:start(1)') })
		$('button.stop').click(function() { rns.run('song().transport:stop()') })
		
		$('.connection').hide()
		$('.controls').show()
	})

	connection.connect()
})
</script>
<style>
.masterVolume { 
	width: 500px;
	height: 20px;
	border: 1px solid black;
}

.masterVolume .slider {
	height: 20px;
	float: left;
	background: red;
}
</style>
</head>
<body>
<h1>Renoise Test Controller</h1>

<div style="display:none" class="controls">
	<b>Main volume (view only)</b> 

	<div class="masterVolume">
		<div class="slider"></div>
	</div>

	<div>
		<button class="play">Play</button>
		<button class="stop">Stop</button>
	</div>
</div>

<div class="connection">No connection...</div>
</body>
</html>